home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / cenviw1.zip / WINUTIL.LIB < prev   
Text File  |  1993-07-14  |  5KB  |  145 lines

  1. // WinUtil.lib - Cmm code wrapper for various useful Windows functions.
  2. //               This is by no means an exhaustive collection, but simply
  3. //               examples.  You may #include this file in your CMM source
  4. //               or you may simply copy the routines you like into your
  5. //               code.  The routines in this file are:
  6. // GetSystemMetrics() - Width and height of various display elements
  7. // GetWindowRect() - return structure containing window coordinates
  8. // MoveWindow() - Move a window to specified coordinates on the screen
  9. // PostMessage() - Post Message to a window
  10. // SendMessage() - Send message to a window
  11. // GetWindowHandle() - get handle for a window based on it's matching title
  12. // GetWindowText() - Get title of a window
  13.  
  14. GetSystemMetrics(Index)
  15.    // return this system metric
  16. {
  17.    #define SM_CXSCREEN         0    // screen width
  18.    #define SM_CYSCREEN         1    // screen height
  19.    #define SM_CXVSCROLL        2
  20.    #define SM_CYHSCROLL        3
  21.    #define SM_CYCAPTION        4
  22.    #define SM_CXBORDER         5
  23.    #define SM_CYBORDER         6
  24.    #define SM_CXDLGFRAME       7
  25.    #define SM_CYDLGFRAME       8
  26.    #define SM_CYVTHUMB         9
  27.    #define SM_CXHTHUMB         10
  28.    #define SM_CXICON           11
  29.    #define SM_CYICON           12
  30.    #define SM_CXCURSOR         13
  31.    #define SM_CYCURSOR         14
  32.    #define SM_CYMENU           15
  33.    #define SM_CXFULLSCREEN     16
  34.    #define SM_CYFULLSCREEN     17
  35.    #define SM_CYKANJIWINDOW    18
  36.    #define SM_MOUSEPRESENT     19
  37.    #define SM_CYVSCROLL        20
  38.    #define SM_CXHSCROLL        21
  39.    #define SM_DEBUG            22
  40.    #define SM_SWAPBUTTON       23
  41.    #define SM_RESERVED1        24
  42.    #define SM_RESERVED2        25
  43.    #define SM_RESERVED3        26
  44.    #define SM_RESERVED4        27
  45.    #define SM_CXMIN            28
  46.    #define SM_CYMIN            29
  47.    #define SM_CXSIZE           30
  48.    #define SM_CYSIZE           31
  49.    #define SM_CXFRAME          32
  50.    #define SM_CYFRAME          33
  51.    #define SM_CXMINTRACK       34
  52.    #define SM_CYMINTRACK       35
  53.    #define SM_CMETRICS         36
  54.    return( DynamicLink("USER","GETSYSTEMMETRICS",SWORD16,PASCAL,Index) );
  55. }
  56.  
  57. GetWindowRect(WindowHandle)
  58.    // return window coordinates in a structure with the following members
  59.    //   .left
  60.    //   .top
  61.    //   .right
  62.    //   .bottom
  63. {
  64.    // set up blob to retrieve four integers
  65.    BLObSize(_rect,4 * 2/*integer size*/);
  66.    DynamicLink("USER","GETWINDOWRECT",SWORD16,PASCAL,WindowHandle,_rect);
  67.    _ret.left = BLObGet(_rect,0,SWORD16);
  68.    _ret.top = BLObGet(_rect,2,SWORD16);
  69.    _ret.right = BLObGet(_rect,4,SWORD16);
  70.    _ret.bottom = BLObGet(_rect,6,SWORD16);
  71.    return(_ret);
  72. }
  73.  
  74. GetClientRect(WindowHandle)
  75.    // return window client-area coordinates in a structure with the following members
  76.    //   .left
  77.    //   .top
  78.    //   .right
  79.    //   .bottom
  80. {
  81.    // set up blob to retrieve four integers
  82.    BLObSize(_rect,4 * 2/*integer size*/);
  83.    DynamicLink("USER","GETCLIENTRECT",SWORD16,PASCAL,WindowHandle,_rect);
  84.    _ret.left = BLObGet(_rect,0,SWORD16);
  85.    _ret.top = BLObGet(_rect,2,SWORD16);
  86.    _ret.right = BLObGet(_rect,4,SWORD16);
  87.    _ret.bottom = BLObGet(_rect,6,SWORD16);
  88.    return(_ret);
  89. }
  90.  
  91.  
  92. MoveWindow(WindowHandle,x,y,width,height,Repaint)
  93.    // move the window to coordinates x,y on the screen, with size width,height.
  94.    // if Repaint is not-False then will repaint window
  95. {
  96.    DynamicLink("USER","MOVEWINDOW",SWORD16,PASCAL,
  97.                WindowHandle,x,y,width,height,Repaint);
  98. }
  99.  
  100. PostMessage(WindowHandle,MessageType,wParam,lParam)
  101. {
  102.    return DynamicLink("USER","POSTMESSAGE",SWORD16,PASCAL,
  103.                       WindowHandle,MessageType,wParam,
  104.                       lParam & 0xFFFF,(lParam >> 16) & 0xFFFF);
  105. }
  106.  
  107. SendMessage(WindowHandle,MessageType,wParam,lParam)
  108. {
  109.    return DynamicLink("USER","SENDMESSAGE",SWORD32,PASCAL,
  110.                       WindowHandle,MessageType,wParam,
  111.                       lParam & 0xFFFF,(lParam >> 16) & 0xFFFF);
  112. }
  113.  
  114. GetWindowText(WindowHandle)
  115.    // return string containing text of this Window handle, or NULL if this window
  116.    // has no text
  117. {
  118.    BLObSize(_buf,200);
  119.    if ( 0 == DynamicLink("USER","GETWINDOWTEXT",SWORD16,PASCAL,
  120.                          WindowHandle,_buf,BLObSize(_buf)-1) ) {
  121.       return(NULL);
  122.    }
  123.    // copy to shorter string and return that
  124.    strcpy(_ret,_buf);
  125.    return(_ret);
  126. }
  127.  
  128. GetWindowHandle(Title)
  129.    // Search for a window to match the string: Title or match title for at
  130.    // least the length of the string. Return the handle of the window as an
  131.    // integer, or return 0 if the window was not found.
  132. {
  133.    _len = strlen(Title);
  134.    if ( NULL == (_winList = WindowList()) ) return 0;
  135.    _count = 1 + GetArraySpan(_winList);
  136.    for ( i = 0; i < _count; i++ ) {
  137.       // compare the title for this window, if it has one
  138.       if ( NULL != (_title = GetWindowText(_winList[i]))
  139.         && 0 == strnicmp(Title,_title,_len) )
  140.          return(_winList[i]);
  141.    }
  142.    return(0);
  143. }
  144.  
  145.